
	use "$dir/rawdata/LSMS Malawi/2004/sec_b.dta", clear // household roster
	compress
	
	/*
		5 MODULE B: HOUSEHOLD ROSTER 
		8 MODULE C: EDUCATION
		11 MODULE D: HEALTH
		16 MODULE E: TIME USE & LABOUR 
		32 MODULE F: HOUSING
		35 MODULE F_1: LAND ROSTER
		47 MODULE H: FOOD SECURITY
		48 MODULE I: NON-FOOD EXPENDITURES – OVER PAST ONE WEEK & ONE MONTH
		49 MODULE J: NON-FOOD EXPENDITURES
		50 MODULE K: NON-FOOD EXPENDITURES OVER PAST 12 MONTHS
		51 MODULE L: DURABLE GOODS
		53 MODULE M: FARM IMPLEMENTS, MACHINERY, AND STRUCTURES
		55 MODULE N: HOUSEHOLD ENTERPRISES
		63 MODULE O: CHILDREN LIVING ELSEWHERE
		65 MODULE P: OTHER INCOME
		67 MODULE Q: GIFTS GIVEN OUT
		68 MODULE R: SOCIAL SAFETY NETS
		70 MODULE S: CREDIT
		72 MODULE T: SUBJECTIVE ASSESSMENT OF WELL-BEING 
		74 MODULE U: SHOCKS & COPING STRATEGIES
		75 MODULE V: CHILD ANTHROPOMETRY
		76 MODULE W: DEATHS
		77 MODULE X: FILTER QUESTIONS FOR AGRICULTURE &
		FISHERY QUESTIONNAIRES
	*/

	// Consumption
	merge m:1 case_id 																				///
		using "$dir/rawdata/LSMS Malawi/2004/ihs2_exp.dta", 								///
		assert(matched) nogen	

	// Health
	merge 1:1 case_id memid 																		///
		using "$dir/rawdata/LSMS Malawi/2004/sec_d.dta", 									///
		keep(master matched) nogen

	// Time use and labor
	merge 1:1 case_id memid 																		///
		using "$dir/rawdata/LSMS Malawi/2004/sec_e.dta", 									///
		keep(master matched) nogen
	
	// Subjective well-being
	merge m:1 case_id																				///
		using "$dir/rawdata/LSMS Malawi/2004/sec_aa.dta", 									///
		keep(master matched) nogen 

	rename hhid hhid_orig
	rename case_id hhid
	rename memid indiv
	
	 ** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
			gen w2_inhh=1 // FIXME: No specific question asking this
		
		** Age
			gen w2_age=b05a
			
		** Household size
			gen temp=1 if w2_inhh==1
			bys hhid: egen w2_hh_size=total(temp)
			drop temp

		** Number of children 12 or younger
			gen temp=1 if w2_age<=12 & w2_inhh==1
			bys hhid: egen w2_hh_under12=total(temp)
			drop temp

		** Number of youth 18 or younger
			gen temp=1 if w2_age<=18 & w2_inhh==1
			bys hhid: egen w2_hh_under18=total(temp)
			drop temp

		** Number of adults 60 or older
			gen temp=1 if w2_age>=60 & !missing(w2_age) & w2_age!=999 & w2_inhh==1
			bys hhid: egen w2_hh_over60=total(temp)
			drop temp

		** Adults 12 to 60
			gen temp=1 if w2_age>12 & w2_age<60 & !missing(w2_age) & w2_age!=999 & w2_inhh==1
			bys hhid: egen w2_hh_12to60=total(temp)
			drop temp

		** Marital status
			gen w2_married=(b23==1 | b23==2) if !missing(b23)
			gen w2_married_monog=(b23==1) if !missing(b23)
			gen w2_married_polyg=(b23==2) if !missing(b23)

		** Female
			gen w2_female=(b03==2) if !missing(b03)

		** Age of spouse
			sum indiv
			forvalues x=1/`r(max)' {
				gen age_person`x'_temp=w2_age if indiv==`x' & !missing(w2_age)
				bys hhid: egen age_person`x'=max(age_person`x'_temp)
				drop age_person`x'_temp
			}

		** Average age of others in the household
			sum indiv 
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if indiv==`x'
			}
			egen w2_hh_avgage=rowmean(age_person*)
			
		** Spouse age
			sum indiv
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if b26a!=`x'
			}
			egen w2_spouse_age=rowmean(age_person*)

		** Age gap
			gen w2_spouse_agegap=w2_age-w2_spouse_age

		** Birth year
			gen w2_birthyear=b06c
			recode w2_birthyear 9999=. 9998=.
			replace w2_birthyear=2004-w2_age if missing(w2_birthyear)
			
	***********
	***********
	
	** Geographic information
	
		gen w2_urban=(reside==0) if !missing(reside)
		
	** Consumption
	
		egen w2_conspc=rowtotal(exp_cat*)
		replace w2_conspc=w2_conspc/hhsize
		
	***********
	***********

	** LABOR

		** Worked for a non-HH member
			gen w2_work_outsideHH1=e11>0 if !missing(e11) // casual part-time
			gen w2_work_outsideHH2=e12>0 if !missing(e12) // wage or salary labor
		
			egen w2_work_outsideHH=rowmax(w2_work_outsideHH1 w2_work_outsideHH2)
			
			gen w2_work_outsideHH1_hrs=e11 if !missing(e11) // casual part-time
			gen w2_work_outsideHH2_hrs=e12 if !missing(e12) // wage or salary labor
			
			egen w2_work_outsideHH_hrs=rowtotal(w2_work_outsideHH1_hrs w2_work_outsideHH2_hrs), mi 
			replace w2_work_outsideHH_hrs=0 if w2_work_outsideHH==0
			
		** Worked in agriculture for a HH member
			gen w2_work_agHH=e08>0 if !missing(e08)
			
			gen w2_work_agHH_hrs=e08 if !missing(e08)
			replace w2_work_agHH_hrs=0 if w2_work_agHH==0
			
		** Worked in HH business
			gen w2_work_bizHH1=e09>0 if !missing(e09) // run biz
			gen w2_work_bizHH2=e10>0 if !missing(e10) // help in biz
			
			egen w2_work_bizHH=rowmax(w2_work_bizHH1 w2_work_bizHH2)
			
			gen w2_work_bizHH1_hrs=e09 if !missing(e09) // run biz
			gen w2_work_bizHH2_hrs=e10 if !missing(e10) // help in biz
					
			egen w2_work_bizHH_hrs=rowtotal(w2_work_bizHH1_hrs w2_work_bizHH1_hrs), mi
			replace w2_work_bizHH_hrs=0 if w2_work_bizHH==0
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w2_worked_last7days=rowmax(w2_work_outsideHH w2_work_agHH w2_work_bizHH)
			
		** Hours worked in last 7 days
			egen w2_work_hrs=rowtotal(w2_work_outsideHH_hrs w2_work_agHH_hrs w2_work_bizHH_hrs)
			replace w2_work_hrs=. if missing(w2_work_outsideHH_hrs) & missing(w2_work_agHH_hrs) & missing(w2_work_bizHH_hrs)
				
		** Works in agriculture
			gen w2_work_agri=(w2_work_agHH==1) if !missing(w2_work_agHH)
			
	***********
	***********

	** HEALTH
		
		** Any illness or injury during the last 2 weeks
			gen w2_ill_inj=(d04==1) if !missing(d04)

		** Had to stop usual activity in the past 4 weeks
			gen w2_ill_inj_stopactivity=(d08==1) if !missing(d08)
			replace w2_ill_inj_stopactivity=0 if w2_ill_inj==0
			
	***********
	***********
	
	** SUBJECTIVE WELL-BEING
	
		** Access to health care
			gen w2_healthcare_inadequate=aa04==1 if !missing(aa04)
			
		** Food consumption
			gen w2_foodcons_inadequate=aa01==1 if !missing(aa01)
			
		** Very unsatisfied with life 
			gen w2_life_dissatisfied=aa13==1 if !missing(aa13)
		
	***********
	***********
	
	** SAVE
	
		keep hhid indiv w2*
		order hhid indiv w2*
		save "$dir/data/MLW_w2_individual.dta", replace
